﻿using Apewer.Models;
using Apewer.Network;
using System;
using System.IO;
using System.Net;

namespace Apewer.Web
{

    /// <summary></summary>
    [Serializable]
    public sealed class ApiResponse
    {

        /// <summary>自定义标签。</summary>
        public object Tag { get; set; }

        #region internal

        private object _model = null;
        private Json _data = Json.NewObject();

        internal bool StopReturn = false;

        /// <summary>API 的执行时间。</summary>
        public string Duration { get; set; }

        /// <summary>Application。</summary>
        public string Application { get; set; }

        /// <summary>Function。</summary>
        public string Function { get; set; }

        /// <summary>Random。</summary>
        public string Random { get; set; }

        #endregion

        #region user

        /// <summary>头。</summary>
        public HttpHeaders Headers { get; set; } = new HttpHeaders();

        /// <summary>Cookies。</summary>
        public CookieCollection Cookies { get; set; } = new CookieCollection();

        /// <summary>获取或设置输出模型。</summary>
        public object Model
        {
            get { return _model; }
            set
            {
                RuntimeUtility.Dispose(_model);
                _model = value;
            }
        }

        /// <summary>当响应 Json 时，强制缩进排版。</summary>
        public bool Indented { get; set; }

        /// <summary>状态。</summary>
        public string Status { get; set; }

        /// <summary>消息。</summary>
        public string Message { get; set; }

        /// <summary>自定义数据。</summary>
        public Json Data
        {
            get { return _data; }
            set { _data = value ?? Json.NewObject(); }
        }

        /// <summary>设置 Data 的属性。</summary>
        public string this[string name] { get => Data[name]; set => Data[name] = value; }

        #endregion

        #region Function

        /// <summary>设置输出前的检查。</summary>
        public ApiPreOutput PreOutput { get; set; }

        #endregion

    }

}

